// pages/monitoring/monitoring.js
var wxCharts = require('../../../utils/wxcharts.js');
import request from '../../../utils/config.js';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    projectId: '',
    windowWidth: wx.getSystemInfoSync().windowWidth,
    height: wx.getSystemInfoSync().windowHeight/2-24
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log("options=====", options)
    this.setData({ projectId: options.projectId})
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getChartVo()
  },
  getChartVo: function () {
    let _this = this;
    request.requestMisApi('get', "projectServicesRecord/getChartVo/" + this.data.projectId, {}, (res) => {
      if (res.code == '00') {
        let resObj = JSON.parse(res.body);
        console.log(resObj);
        if (resObj.fieldList && resObj.fieldList.length > 0) {
          _this.setChar1(resObj.fieldList);
        }
        if (resObj.modeList && resObj.modeList.length > 0) {
          _this.setChar2(resObj.modeList);
        }
      }
    }, (res) => {
      console.log("接口错误=", res)
    });
  },
  setChar1: function (list) {
    let data = []
    list.map((item) => {
      data.push({
        name: item.serviceFieldName,
        data: item.serviceDuration
      })
    })
    new wxCharts({
      animation: true, //是否有动画
      canvasId: 'canvas1',
      type: 'pie',
      series: data,
      width: this.data.windowWidth,
      height: this.data.height,
      dataLabel: true,
    });
  },
  setChar2: function (list) {
    let data = []
    list.map((item) => {
      data.push({
        name: item.serviceModeName,
        data: item.serviceDuration
      })
    })
    new wxCharts({
      animation: true, //是否有动画
      canvasId: 'canvas2',
      type: 'pie',
      series: data,
      width: this.data.windowWidth,
      height: this.data.height,
      dataLabel: true,
    });
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.stopPullDownRefresh()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})